﻿define(["plugins/router", "bootstrap"], function(router, bootstrap) {
  var routes = [
    {
      route: ["", "hello-world"],
      title: "Hello World",
      moduleId: "d1/app/viewmodels/hello-world",
      nav: true
    },
    {
      route: "coin-winner",
      title: "投币赢家",
      nav: true,
      hasChild: true
    },
    {
      route: "coin-winner/default",
      moduleId: "d1/app/viewmodels/coin-winner/one",
      title: "默认模式",
      nav: true,
      parentHash: "coin-winner"
    },
    {
      route: "coin-winner/virtual-list",
      moduleId: "d1/app/viewmodels/coin-winner/two",
      title: "虚拟列表模式",
      nav: true,
      parentHash: "coin-winner"
    },
    {
      route: "coin-winner/virtual-panel",
      moduleId: "d1/app/viewmodels/coin-winner/three",
      title: "虚拟面板模式",
      nav: true,
      parentHash: "coin-winner"
    },
    {
      route: "paper*childRoute",
      title: "纸",
      moduleId: "d1/app/viewmodels/paper/shell",
      nav: true
    },
    {
      route: "life-cycle",
      title: "生命周期",
      nav: true,
      hasChild: true
    },
    {
      route: "life-cycle-a",
      moduleId: "d1/app/viewmodels/life-cycleA",
      title: "生命周期A",
      nav: true,
      parentHash: "life-cycle"
    },
    {
      route: "life-cycle-b",
      moduleId: "d1/app/viewmodels/life-cycleB",
      title: "生命周期B",
      nav: true,
      parentHash: "life-cycle"
    },
    {
      route: "bug-test",
      moduleId: "d1/app/viewmodels/bug-test",
      title: "bug 测试",
      nav: true
    },
    {
      route: "more-nav",
      moduleId: "d1/app/viewmodels/more-nav",
      title: "更多导航",
      nav: true
    }
  ];

  return {
    router: router,
    activate: function() {
      return router
        .map(routes)
        .buildNavigationModel()
        .mapUnknownRoutes("d1/app/viewmodels/error", "not-found")
        .activate();
    },
    getRootRouter: function() {
      return ko.utils.arrayFilter(router.navigationModel(), function(route) {
        return route.parentHash === undefined;
      });
    },
    getChildRouter: function(parentHash) {
      return ko.utils.arrayFilter(router.navigationModel(), function(route) {
        return "#" + route.parentHash == parentHash;
      });
    }
  };
});
